package cn.jdy.plugins.service;

import cn.jdy.framework.db.hibernate.BaseDao;
import cn.jdy.plugins.entity.Discuss;

import org.hibernate.SQLQuery;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.Query;

import java.util.List;

/**
 * @author wuzhiliang
 * @title : 商机评论信息操作实现
 */
@Service
@Transactional
public class DiscussService extends BaseDao<Discuss> {

	/**
	 * 查询评论信息
	 *
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Discuss> query(Long businessId) {
	  SQLQuery query = super.em().createSQLQuery("select t1.id, t1.userid, t1.businessid, t1.context, date_format(t1.sendtime,'%d/%m/%Y %H:%i') as createTime," +
				"IF(type=4,(select t2.username from member t2 where t2.id = t1.userid),(select t3.username from user t3 where t3.id = t1.userid)) as username" +
				"from info t1 where  t1.businessid = '" + businessId + "' order by createTime desc");
		return query.list();
	}

}
